package org.seal.security.cros_csrf_shop;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 模拟商店业务
 * @author seal
 */
@RestController
@RequestMapping("/shop")
public class ShopController {

    private int phoneNum = 10;

    /**
     * 获取手机数量
     * @return
     */
    @RequestMapping(method = RequestMethod.GET, value = "/")
    public int getPhoneNum(){
        return phoneNum;
    }

     /**
     * 消费手机
     */
    @RequestMapping(method = RequestMethod.POST, value = "/")
    public void buyPhone(){
        phoneNum -= 1;
    }

    /**
     * 退还手机
     */
    @RequestMapping(method = RequestMethod.DELETE, value = "/")
    public void giveBack(){
        phoneNum += 1;
    }
}
